"""
存放一些共用的方法


"""

# 使用functiontool

import functools

# 定义一个获取当前用户的登陆状态
from flask import session, g

from info import db


def user_data_session(f):
    @functools.wraps(f)
    def wrapper(*args, **kwargs):
        user_id = session.get("user_id")

        user = None

        if user_id:
            from info.models import User
            # user = db.session.query(User).get(user_id)
            user = User.query.get(user_id)

        g.user = user

        return f(*args, **kwargs)

    return wrapper
